package com.googlecode.afdbaccess.web.portal.webcontent.list_rows.list_rows_table_data;

import javax.annotation.security.RolesAllowed;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;

import org.jboss.resteasy.annotations.cache.Cache;

import com.googlecode.afdbaccess.config.injectconfig.ManagedRequestTransaction;
import com.googlecode.afdbaccess.web.common.db.converters.SimpleExtJsJsonResponseConverter;
import com.googlecode.afdbaccess.web.common.interceptors.DatabaseAccessing;
import com.googlecode.afdbaccess.web.common.interceptors.RequestLogged;
import com.googlecode.afdbaccess.web.common.json.ExtJsJsonResponse;

@RolesAllowed("theRole")
@RequestLogged
@DatabaseAccessing
@Path("list-rows/list-rows-table-data")
public class ListRowsTableGetRest {
    @Inject
    private ManagedRequestTransaction t;

    @GET
    @Cache(maxAge=0)
    @Produces("application/json")
    public ExtJsJsonResponse get(@SuppressWarnings("unused") @Context HttpServletRequest request) throws Exception {
        String sql =
            "SELECT\n" +
            "  webTable.webTable_id id,\n" +
            "  webTable.stringAttribute\n" +
            "FROM\n" +
            "  webTable\n" +
            "ORDER BY\n" +
            "  webTable.webTable_id\n";

        return t.executeQuery(sql, null, SimpleExtJsJsonResponseConverter.class, 0);
    }
}
